<?php
/**
 * 컨텐츠 코멘트 관련 model
 * 
 * @author gudals
 * @since 2013-08-08
 */

class modelContContentsComment extends modelContBase
{
    /**
     * 코멘트 등록
     * 
     * @param array $aReq  등록정보
     * @return Ambigous <NULL, multitype:void , void, unknown>
     */
    public function insert($aReq)
    {
        $aReq = addSlashesVariable($aReq, array('comment_desc'));
        
        if (chkTypesVariable(array('int' => $aReq['user_num'], 'int' => $aReq['contents_num'], 'string' => $aReq['comment_desc'])) === false) {
            return false;
        }
        
        $sQuery = "
            insert into bf_contents_comment (
                contents_num,
                comment_desc,
                user_num,
                reg_ts
            ) values (
                '".$aReq['contents_num']."',
                '".$aReq['comment_desc']."',
                '".$aReq['user_num']."',
                UNIX_TIMESTAMP()
            )
        ";
        
        return $this->executeQuery($sQuery, 'exec');
    }
    
    /**
     * 컨텐츠 코멘트 리스트
     * 
     * @param string $sContentsNumList 컨텐츠 번호 리스트 1, 2, 3, 4
     * @return Ambigous <NULL, multitype:void , void, unknown>
     */
    public function getListByContentsNums($sContentsNumList)
    {
        $sQuery = "
            select
                comment_num,
                contents_num,
                comment_desc,
                user_num,
                reg_ts
            from
                bf_contents_comment
            where
                comment_status = 'Y'
            and
                contents_num in (".$sContentsNumList.")
            order by
                comment_num asc
        ";
        
        return $this->executeQuery($sQuery, 'rows');
    }
    
    /**
     * 코멘트 리스트
     * 
     * @param int $iContentsNum 컨텐츠 번호
     * @return boolean|Ambigous <NULL, multitype:void , void, unknown>
     */
    public function getList($iContentsNum)
    {
        if (chkTypesVariable(array('int' => $iContentsNum)) === false) {
            return false;
        }
        
        $sQuery = "
            select
                comment_num,
                contents_num,
                comment_desc,
                user_num,
                reg_ts
            from
                bf_contents_comment
            where
                comment_status = 'Y'
            and
                contents_num = '".$iContentsNum."'
            order by
                comment_num asc
        ";
        
        return $this->executeQuery($sQuery, 'rows');
    }
}